package com.costeaalex.blueserver.interfaces.setup;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;

import com.costeaalex.blueserver.setup.SetupServerApp;

public class ScreenSetupSelectConnection extends JPanel
	{

	private static final long	serialVersionUID	= -3265561594041554698L;
	private JLabel instructions;
	private JButton serial;
	private JButton bluecove;
	private SetupServerApp sSAL;
	private Listener l;
	private boolean actionPerformed=false;
	
	public ScreenSetupSelectConnection(SetupServerApp sSA)
		{
		super();
		l=new Listener();
		sSAL=sSA;
		JLabel jTAS=new JLabel(" Setup ");
		
		this.add(jTAS, BorderLayout.NORTH);
		
		JPanel inst=new JPanel();
		inst.setLayout(new BorderLayout(5, 5));
		instructions=new JLabel("Please select your desired way to connect to the remote control:");
		JSeparator s1=new JSeparator();
		JSeparator s2=new JSeparator();
		inst.add(s1, BorderLayout.NORTH);
		inst.add(instructions, BorderLayout.CENTER);
		inst.add(s2, BorderLayout.SOUTH);
		
		this.add(inst, BorderLayout.CENTER);
		
		JLabel recommended=new JLabel("Recommended");
		serial=new JButton("Default serial port");
		serial.addActionListener(l);
		bluecove=new JButton("Bluecove serial port");
		bluecove.addActionListener(l);
		JPanel body=new JPanel();
		body.setLayout(new BorderLayout(5,5));
		JPanel serialP=new JPanel();
			serialP.setLayout(new BorderLayout(5,5));
			serialP.add(serial, BorderLayout.WEST);
			serialP.add(recommended, BorderLayout.EAST);
		body.add(serialP, BorderLayout.CENTER);
		body.add(bluecove, BorderLayout.SOUTH);
		
		this.add(body, BorderLayout.SOUTH);
		}

	public class Listener implements ActionListener
		{
		public void actionPerformed(ActionEvent a)
			{
			if(!actionPerformed)
				{
				actionPerformed=true;
				if(a.getSource()==serial)
					{
					sSAL.tryServer=1;
					}
				
				if(a.getSource()==bluecove)
					{
					sSAL.tryServer=2;
					}
				}
			}
		}
	}
